/**
 * Created by Luzanzan on 2016/12/23.
 */
angular.module("login",[])
    .controller("login", function($scope,$http){
        $scope.dengluCSS=true;
        $scope.registCSS=false;
        $scope.loginn=true;
        $scope.zhucee=false;
        $scope.zhuceCSS=function(){
            // document.getElementById('qlogin').style.display="block";
            // document.getElementById('web_qr_login').style.display="none";
            $scope.dengluCSS=false;
            $scope.registCSS=true;
            $scope.loginn=false;
            $scope.zhucee=true;
        }
        $scope.loginCSS= function(){
            // document.getElementById('qlogin').style.display="none";
            // document.getElementById('web_qr_login').style.display="block";
            $scope.dengluCSS=true;
            $scope.registCSS=false;
            $scope.loginn=true;
            $scope.zhucee=false;
        }
        $scope.login=function(){
            console.log($scope.lusername,$scope.lpassword)
            $http({
                method:'POST',
                url:IP+"",
                params:{
                    username:$scope.lusername,
                    password:$scope.lpassword
                }
            }).success(function(data){
                if(data){
                    window.location.href="cheatRoom.html?="+$scope.llusername;
                }else{
                    alert("登录失败，请检查账户名密码");
                    return;
                }
            })
        }
        $scope.regist=function(){
            if($scope.password!=$scope.surepassword){
                alert("两次密码不一致");
                return;
            }else{
                console.log("OK");
                $http({
                    method:'POST',
                    url:IP+'',
                    params:{
                        username:$scope.username,
                        password:$scope.password,
                        age:$scope.userage,
                        email:$scope.useremail
                    }
                }).success(function(data){
                    console.log(data);
                    if(data.errorcode==0){
                        alert("注册成功");
                        window.location.reload();
                    }else{
                        alert("注册失败");
                    }
                })
            }
        }
    })